package com.gs.logviewer.gui.frame;

import com.gs.logviewer.gui.comps.LogViewerPanel;
import java.awt.event.ActionEvent;
import java.awt.event.WindowEvent;
import java.io.File;
import javax.swing.JTabbedPane;

import javax.swing.event.ChangeEvent;

/**
 *
 * @author sabuj.das
 */
public class LoadLog4jInternalFrame extends LogViewerInternalFrame {

    public LoadLog4jInternalFrame() {
        initComponents();
        getLogFilesTabbedPane().addTab("gfgf", new LogViewerPanel());
        getLogFilesTabbedPane().updateUI();
    }


    @SuppressWarnings("unchecked")
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        log4jLoaderToolBar = new javax.swing.JToolBar();
        loadLog4jButton = new javax.swing.JButton();
        refreshButton = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        saveLogButton = new javax.swing.JButton();
        saveAllLogButton = new javax.swing.JButton();
        saveAsLogButton = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JToolBar.Separator();
        cutLogButton = new javax.swing.JButton();
        copyLogButton = new javax.swing.JButton();
        pasteLogButton = new javax.swing.JButton();
        selectAllLogButton = new javax.swing.JButton();
        jSeparator5 = new javax.swing.JToolBar.Separator();
        undoButton = new javax.swing.JButton();
        redoButton = new javax.swing.JButton();
        jSeparator3 = new javax.swing.JToolBar.Separator();
        jLabel1 = new javax.swing.JLabel();
        logLevelSlider = new javax.swing.JSlider();
        currentLogLevelLabel = new javax.swing.JLabel();
        jSeparator4 = new javax.swing.JToolBar.Separator();
        filterLogButton = new javax.swing.JButton();
        logFilesPanel = new javax.swing.JPanel();
        logFilesTabbedPane = new javax.swing.JTabbedPane();

        setForeground(java.awt.Color.white);
        setTitle("Load Log4j");
        getContentPane().setLayout(new java.awt.GridBagLayout());

        log4jLoaderToolBar.setFloatable(false);
        log4jLoaderToolBar.setRollover(true);
        log4jLoaderToolBar.setName("log4jLoaderToolBar"); // NOI18N

        loadLog4jButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Download.png"))); // NOI18N
        loadLog4jButton.setText("Load");
        loadLog4jButton.setFocusable(false);
        loadLog4jButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        loadLog4jButton.setName("loadLog4jButton"); // NOI18N
        loadLog4jButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        log4jLoaderToolBar.add(loadLog4jButton);

        refreshButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/reload_green.png"))); // NOI18N
        refreshButton.setText("Refresh");
        refreshButton.setFocusable(false);
        refreshButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        refreshButton.setName("refreshButton"); // NOI18N
        refreshButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        log4jLoaderToolBar.add(refreshButton);

        jSeparator1.setName("jSeparator1"); // NOI18N
        log4jLoaderToolBar.add(jSeparator1);

        saveLogButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/save.gif"))); // NOI18N
        saveLogButton.setText("Save");
        saveLogButton.setFocusable(false);
        saveLogButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        saveLogButton.setName("saveLogButton"); // NOI18N
        saveLogButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        log4jLoaderToolBar.add(saveLogButton);

        saveAllLogButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/saveall.gif"))); // NOI18N
        saveAllLogButton.setText("Save All");
        saveAllLogButton.setFocusable(false);
        saveAllLogButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        saveAllLogButton.setName("saveAllLogButton"); // NOI18N
        saveAllLogButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        log4jLoaderToolBar.add(saveAllLogButton);

        saveAsLogButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/saveas_edit.gif"))); // NOI18N
        saveAsLogButton.setText("Save As");
        saveAsLogButton.setFocusable(false);
        saveAsLogButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        saveAsLogButton.setName("saveAsLogButton"); // NOI18N
        saveAsLogButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        log4jLoaderToolBar.add(saveAsLogButton);

        jSeparator2.setName("jSeparator2"); // NOI18N
        log4jLoaderToolBar.add(jSeparator2);

        cutLogButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/cut.gif"))); // NOI18N
        cutLogButton.setText("Cut");
        cutLogButton.setFocusable(false);
        cutLogButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        cutLogButton.setName("cutLogButton"); // NOI18N
        cutLogButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        log4jLoaderToolBar.add(cutLogButton);

        copyLogButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/copy.gif"))); // NOI18N
        copyLogButton.setText("Copy");
        copyLogButton.setFocusable(false);
        copyLogButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        copyLogButton.setName("copyLogButton"); // NOI18N
        copyLogButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        log4jLoaderToolBar.add(copyLogButton);

        pasteLogButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/paste.gif"))); // NOI18N
        pasteLogButton.setText("Paste");
        pasteLogButton.setFocusable(false);
        pasteLogButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        pasteLogButton.setName("pasteLogButton"); // NOI18N
        pasteLogButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        log4jLoaderToolBar.add(pasteLogButton);

        selectAllLogButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/selectall.gif"))); // NOI18N
        selectAllLogButton.setText("Select All");
        selectAllLogButton.setFocusable(false);
        selectAllLogButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        selectAllLogButton.setName("selectAllLogButton"); // NOI18N
        selectAllLogButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        log4jLoaderToolBar.add(selectAllLogButton);

        jSeparator5.setName("jSeparator5"); // NOI18N
        log4jLoaderToolBar.add(jSeparator5);

        undoButton.setText("Undo");
        undoButton.setFocusable(false);
        undoButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        undoButton.setName("undoButton"); // NOI18N
        undoButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        log4jLoaderToolBar.add(undoButton);

        redoButton.setText("Redo");
        redoButton.setFocusable(false);
        redoButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        redoButton.setName("redoButton"); // NOI18N
        redoButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        log4jLoaderToolBar.add(redoButton);

        jSeparator3.setName("jSeparator3"); // NOI18N
        log4jLoaderToolBar.add(jSeparator3);

        jLabel1.setText("Log Level: ");
        jLabel1.setName("jLabel1"); // NOI18N
        log4jLoaderToolBar.add(jLabel1);

        logLevelSlider.setForeground(new java.awt.Color(0, 51, 51));
        logLevelSlider.setMaximum(5);
        logLevelSlider.setPaintLabels(true);
        logLevelSlider.setPaintTicks(true);
        logLevelSlider.setSnapToTicks(true);
        logLevelSlider.setMaximumSize(new java.awt.Dimension(180, 31));
        logLevelSlider.setMinimumSize(new java.awt.Dimension(180, 31));
        logLevelSlider.setName("logLevelSlider"); // NOI18N
        logLevelSlider.setPreferredSize(new java.awt.Dimension(180, 31));
        log4jLoaderToolBar.add(logLevelSlider);

        currentLogLevelLabel.setText("DEBUG");
        currentLogLevelLabel.setName("currentLogLevelLabel"); // NOI18N
        log4jLoaderToolBar.add(currentLogLevelLabel);

        jSeparator4.setName("jSeparator4"); // NOI18N
        log4jLoaderToolBar.add(jSeparator4);

        filterLogButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/systemfilterpool.gif"))); // NOI18N
        filterLogButton.setText("Filter");
        filterLogButton.setFocusable(false);
        filterLogButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        filterLogButton.setName("filterLogButton"); // NOI18N
        filterLogButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        log4jLoaderToolBar.add(filterLogButton);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 1.0;
        getContentPane().add(log4jLoaderToolBar, gridBagConstraints);

        logFilesPanel.setName("logFilesPanel"); // NOI18N
        logFilesPanel.setLayout(new java.awt.BorderLayout());

        logFilesTabbedPane.setName("logFilesTabbedPane"); // NOI18N
        logFilesTabbedPane.setMinimumSize(new java.awt.Dimension(480, 400));
        logFilesTabbedPane.setPreferredSize(new java.awt.Dimension(480, 400));
        logFilesPanel.add(logFilesTabbedPane, java.awt.BorderLayout.CENTER);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        getContentPane().add(logFilesPanel, gridBagConstraints);

        pack();
    }

    private javax.swing.JButton copyLogButton;
    private javax.swing.JLabel currentLogLevelLabel;
    private javax.swing.JButton cutLogButton;
    private javax.swing.JButton filterLogButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JToolBar.Separator jSeparator2;
    private javax.swing.JToolBar.Separator jSeparator3;
    private javax.swing.JToolBar.Separator jSeparator4;
    private javax.swing.JToolBar.Separator jSeparator5;
    private javax.swing.JButton loadLog4jButton;
    private javax.swing.JToolBar log4jLoaderToolBar;
    private javax.swing.JPanel logFilesPanel;
    private javax.swing.JTabbedPane logFilesTabbedPane;
    private javax.swing.JSlider logLevelSlider;
    private javax.swing.JButton pasteLogButton;
    private javax.swing.JButton redoButton;
    private javax.swing.JButton refreshButton;
    private javax.swing.JButton saveAllLogButton;
    private javax.swing.JButton saveAsLogButton;
    private javax.swing.JButton saveLogButton;
    private javax.swing.JButton selectAllLogButton;
    private javax.swing.JButton undoButton;
    // End of variables declaration

    @Override
    public void windowOpened(WindowEvent e) {
    }

    @Override
    public void windowClosing(WindowEvent e) {
    }

    @Override
    public void windowClosed(WindowEvent e) {
    }

    @Override
    public void windowDeiconified(WindowEvent e) {
    }

    @Override
    public void windowActivated(WindowEvent e) {
    }

    @Override
    public void actionPerformed(ActionEvent e) {
    }

    @Override
    public void stateChanged(ChangeEvent e) {
    }

    public void showLogFile(File logFile) {
        if (logFile == null) {
            return;
        }
        if (!logFile.exists()) {
            return;
        }
        getLogFilesTabbedPane().addTab(logFile.getName(), new LogViewerPanel());
        getLogFilesTabbedPane().updateUI();
    }

    public JTabbedPane getLogFilesTabbedPane() {
        return logFilesTabbedPane;
    }

}
